package com.zszedu.web.advice;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

//异常处理机制注解
@ControllerAdvice
public class MyExceptionHandler {

    //接收异常，并进行处理
    @ExceptionHandler({Exception.class})
    @ResponseBody
    public Map exceptionHandler(Exception e) {
        return new HashMap(){{
            put("success",false);
            put("msg",e.getMessage());
        }};
    }
}
